package cn.myweb.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class MyTimerInterceptor extends AbstractInterceptor {
    @Override
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        //开始时间
        long startTime= System.currentTimeMillis();
        System.out.println("执行Action之前的工作,开始时间: "+ startTime);
        //执行拦截器之后接续执行Action
        String result = actionInvocation.invoke();
        //执行action后,的计算并输出执行时间
        long endTime= System.currentTimeMillis();
        long execTime = endTime - startTime;
        System.out.println("执行Action之前的工作,开始时间:"+endTime);
        System.out.println("总用时: "+ execTime);
        return result;
    }
}
